<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
	<script type="text/javascript">
		//改变this指向
		//call(this的指向， 参数1,参数2) 
		//apply(this的指向, [参数1，参数2]) 
		//bind(this的指向, 参数1,参数2)() 需要手动调用

		let obj = {
			name: "阿三",
			age: 18,
			fn: function(love) {
				console.log(this.name + "love" + love, this.age)
			}
        }

		let obj2 = {
			name: "阿四",
			age: 66
		}

		obj.fn("蜥蜴")
		//this的指向从obj变成了obj2
		obj.fn.call(obj2, "电饭煲")
		obj.fn.apply(obj2, ["电磁炉"])
		obj.fn.bind(obj2, "微波炉")()

		//

		function Animal(name) {
			this.name = name
			this.showname = function() {
				console.log(this.name)
			}
		}

		Animal.prototype.getName = function() {
			console.log("dog")
		}

		function Dog(name) {
			Animal.call(this, name)
		}

		let dog = new Dog("Crazy Dog")
		dog.showname()
		//原型上的不能继承
		// dog.getName()//报错
	</script>
</body>
</html>